import {Controller, All, Req} from '@nestjs/common';
import {response} from "../lib/response/response";
import {BookManagerService} from "./service";

@Controller('book_manager')
export class BookManagerController {
  constructor(
      private readonly bookManagerService: BookManagerService
  ) {}

  @All('category_list')
  async getCategoryList(@Req() request) {
    return response(0, (await this.bookManagerService.getCategoryNameList({
      sort: {"count": -1}
    })).map(x=>x.name));
  }

  @All('refresh_category')
  async refreshCategory(@Req() request) {
    return response(this.bookManagerService.refreshCategory() ? 0 : 1);
  }

  @All('test')
  async test(@Req() request) {
    return response(0);
  }



  // @All('update_category_order')
  // async updateOrder(@Req() request) {
  //     let dto = new CreateCatDto1();
  //     dto.name= "aaaaa";
  //     return response(this.bookManagerService.updateCategory(dto) ? 0 : 1);
  // }
}
